<h1 id="tree">tree</h1>
<p>树状图列出目录的内容</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>tree命令</strong> 以树状图列出目录的内容。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">tree(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<div class="sourceCode" id="cb2"><pre><code class="language-bash"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="ex">-------</span> 列表选项 -------</a>
<a class="sourceLine" id="cb2-2" data-line-number="2"><span class="ex">-a</span>            # 显示所有文件和目录。</a>
<a class="sourceLine" id="cb2-3" data-line-number="3"><span class="ex">-d</span>            # 先是目录名称而非文件。</a>
<a class="sourceLine" id="cb2-4" data-line-number="4"><span class="ex">-l</span>            # 如遇到性质为符号连接的目录，直接列出该连接所指向的原始目录。</a>
<a class="sourceLine" id="cb2-5" data-line-number="5"><span class="ex">-f</span>            # 在每个文件或目录之前，显示完整的相对路径名称。</a>
<a class="sourceLine" id="cb2-6" data-line-number="6"><span class="ex">-x</span>            # 将范围局限在现行的文件系统中，若指定目录下的某些子目录，其存放于另一个文件系统上，则将该目录予以排除在寻找范围外。</a>
<a class="sourceLine" id="cb2-7" data-line-number="7"><span class="ex">-L</span> level      # 限制目录显示层级。</a>
<a class="sourceLine" id="cb2-8" data-line-number="8"><span class="ex">-R</span>            # Rerun tree when max dir level reached.</a>
<a class="sourceLine" id="cb2-9" data-line-number="9"><span class="ex">-P</span> pattern    # <span class="op">&lt;</span>范本样式<span class="op">&gt;</span> 只显示符合范本样式的文件和目录名称。</a>
<a class="sourceLine" id="cb2-10" data-line-number="10"><span class="ex">-I</span> pattern    # Do not list files that match the given pattern.</a>
<a class="sourceLine" id="cb2-11" data-line-number="11"><span class="ex">--ignore-case</span> <span class="co"># Ignore case when pattern matching.</span></a>
<a class="sourceLine" id="cb2-12" data-line-number="12"><span class="ex">--matchdirs</span>   # Include directory names in -P pattern matching.</a>
<a class="sourceLine" id="cb2-13" data-line-number="13"><span class="ex">--noreport</span>    # Turn off file/directory count at end of tree listing.</a>
<a class="sourceLine" id="cb2-14" data-line-number="14"><span class="ex">--charset</span> X   # Use charset X for terminal/HTML and indentation line output.</a>
<a class="sourceLine" id="cb2-15" data-line-number="15"><span class="ex">--filelimit</span> <span class="co"># # Do not descend dirs with more than # files in them.</span></a>
<a class="sourceLine" id="cb2-16" data-line-number="16"><span class="ex">--timefmt</span> <span class="op">&lt;</span>f<span class="op">&gt;</span> <span class="co"># Print and format time according to the format &lt;f&gt;.</span></a>
<a class="sourceLine" id="cb2-17" data-line-number="17"><span class="ex">-o</span> filename   # Output to file instead of stdout.</a>
<a class="sourceLine" id="cb2-18" data-line-number="18"><span class="ex">--------</span> 文件选项 ---------</a>
<a class="sourceLine" id="cb2-19" data-line-number="19"><span class="ex">-q</span>            # 用“？”号取代控制字符，列出文件和目录名称。</a>
<a class="sourceLine" id="cb2-20" data-line-number="20"><span class="ex">-N</span>            # 直接列出文件和目录名称，包括控制字符。</a>
<a class="sourceLine" id="cb2-21" data-line-number="21"><span class="ex">-Q</span>            # Quote filenames with double quotes.</a>
<a class="sourceLine" id="cb2-22" data-line-number="22"><span class="ex">-p</span>            # 列出权限标示。</a>
<a class="sourceLine" id="cb2-23" data-line-number="23"><span class="ex">-u</span>            # 列出文件或目录的拥有者名称，没有对应的名称时，则显示用户识别码。</a>
<a class="sourceLine" id="cb2-24" data-line-number="24"><span class="ex">-g</span>            # 列出文件或目录的所属群组名称，没有对应的名称时，则显示群组识别码。</a>
<a class="sourceLine" id="cb2-25" data-line-number="25"><span class="ex">-s</span>            # 列出文件和目录大小。</a>
<a class="sourceLine" id="cb2-26" data-line-number="26"><span class="ex">-h</span>            # Print the size in a more human readable way.</a>
<a class="sourceLine" id="cb2-27" data-line-number="27"><span class="ex">--si</span>          # Like -h, but use in SI units (powers of 1000)<span class="ex">.</span></a>
<a class="sourceLine" id="cb2-28" data-line-number="28"><span class="ex">-D</span>            # 列出文件或目录的更改时间。</a>
<a class="sourceLine" id="cb2-29" data-line-number="29"><span class="ex">-F</span>            # 在执行文件，目录，Socket，符号连接，管道名称名称，各自加上<span class="st">&quot;*&quot;</span>，<span class="st">&quot;/&quot;</span>，<span class="st">&quot;@&quot;</span>，<span class="st">&quot;|&quot;</span>号。</a>
<a class="sourceLine" id="cb2-30" data-line-number="30"><span class="ex">--inodes</span>      # Print inode number of each file.</a>
<a class="sourceLine" id="cb2-31" data-line-number="31"><span class="ex">--device</span>      # Print device ID number to which each file belongs.</a>
<a class="sourceLine" id="cb2-32" data-line-number="32"><span class="ex">-------</span> 排序选项 -------</a>
<a class="sourceLine" id="cb2-33" data-line-number="33"><span class="ex">-v</span>            # Sort files alphanumerically by version.</a>
<a class="sourceLine" id="cb2-34" data-line-number="34"><span class="ex">-t</span>            # 用文件和目录的更改时间排序。</a>
<a class="sourceLine" id="cb2-35" data-line-number="35"><span class="ex">-c</span>            # Sort files by last status change time.</a>
<a class="sourceLine" id="cb2-36" data-line-number="36"><span class="ex">-U</span>            # Leave files unsorted.</a>
<a class="sourceLine" id="cb2-37" data-line-number="37"><span class="ex">-r</span>            # Reverse the order of the sort.</a>
<a class="sourceLine" id="cb2-38" data-line-number="38"><span class="ex">--dirsfirst</span>   # List directories before files (-U disables)<span class="ex">.</span></a>
<a class="sourceLine" id="cb2-39" data-line-number="39"><span class="ex">--sort</span> X      # Select sort: name,version,size,mtime,ctime.</a>
<a class="sourceLine" id="cb2-40" data-line-number="40"><span class="ex">-------</span> 图形选项 ------</a>
<a class="sourceLine" id="cb2-41" data-line-number="41"><span class="ex">-i</span>            # 不以阶梯状列出文件和目录名称。</a>
<a class="sourceLine" id="cb2-42" data-line-number="42"><span class="ex">-A</span>            # 使用ASNI绘图字符显示树状图而非以ASCII字符组合。</a>
<a class="sourceLine" id="cb2-43" data-line-number="43"><span class="ex">-S</span>            # Print with CP437 (console) <span class="ex">graphics</span> indentation lines.</a>
<a class="sourceLine" id="cb2-44" data-line-number="44"><span class="ex">-n</span>            # Turn colorization off always (-C overrides)<span class="ex">.</span></a>
<a class="sourceLine" id="cb2-45" data-line-number="45"><span class="ex">-C</span>            # 在文件和目录清单加上色彩，便于区分各种类型。</a>
<a class="sourceLine" id="cb2-46" data-line-number="46"><span class="ex">-------</span> XML / HTML / JSON选项 -------</a>
<a class="sourceLine" id="cb2-47" data-line-number="47"><span class="ex">-X</span>            # Prints out an XML representation of the tree.</a>
<a class="sourceLine" id="cb2-48" data-line-number="48"><span class="ex">-J</span>            # Prints out an JSON representation of the tree.</a>
<a class="sourceLine" id="cb2-49" data-line-number="49"><span class="ex">-H</span> baseHREF   # Prints out HTML format with baseHREF as top directory.</a>
<a class="sourceLine" id="cb2-50" data-line-number="50"><span class="ex">-T</span> string     # Replace the default HTML title and H1 header with string.</a>
<a class="sourceLine" id="cb2-51" data-line-number="51"><span class="ex">--nolinks</span>     # Turn off hyperlinks in HTML output.</a>
<a class="sourceLine" id="cb2-52" data-line-number="52"><span class="ex">----</span> 杂项选项 ----</a>
<a class="sourceLine" id="cb2-53" data-line-number="53"><span class="ex">--version</span>     # 输入版本信息。</a>
<a class="sourceLine" id="cb2-54" data-line-number="54"><span class="ex">--help</span>        # 打印使用帮助信息。</a>
<a class="sourceLine" id="cb2-55" data-line-number="55"><span class="ex">--</span>            # Options processing terminator.</a></code></pre></div>
<h3 id="参数">参数</h3>
<p>目录：执行tree指令，它会列出指定目录下的所有文件，包括子目录里的文件。</p>
<h3 id="实例">实例</h3>
<p>列出目录<code>/private/</code> 第一级文件名</p>
<div class="sourceCode" id="cb3"><pre><code class="language-bash"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="ex">tree</span>  /private/ -L 1</a>
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="ex">/private/</span></a>
<a class="sourceLine" id="cb3-3" data-line-number="3">├── <span class="ex">etc</span></a>
<a class="sourceLine" id="cb3-4" data-line-number="4">├── <span class="ex">tftpboot</span></a>
<a class="sourceLine" id="cb3-5" data-line-number="5">├── <span class="ex">tmp</span></a>
<a class="sourceLine" id="cb3-6" data-line-number="6">└── <span class="ex">var</span></a></code></pre></div>
<p>忽略文件夹</p>
<div class="sourceCode" id="cb4"><pre><code class="language-bash"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="ex">tree</span> -I node_modules <span class="co"># 忽略当前目录文件夹node_modules</span></a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="ex">tree</span> -P node_modules <span class="co"># 列出当前目录文件夹node_modules的目录结构</span></a>
<a class="sourceLine" id="cb4-3" data-line-number="3"><span class="ex">tree</span> -P node_modules -L 2 <span class="co"># 显示目录node_modules两层的目录树结构</span></a>
<a class="sourceLine" id="cb4-4" data-line-number="4"><span class="ex">tree</span> -L 2 <span class="op">&gt;</span> /home/www/tree.txt <span class="co"># 当前目录结果存到 tree.txt 文件中</span></a></code></pre></div>
<p>忽略多个文件夹</p>
<div class="sourceCode" id="cb5"><pre><code class="language-bash"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="ex">tree</span> -I <span class="st">&#39;node_modules|icon|font&#39;</span> -L 2</a></code></pre></div>
<!-- Linux命令行搜索引擎：https://jaywcjlove.github.io/linux-command/ -->
